package com.gameley.dmgtpf.kernel.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.gameley.dmgtpf.common.core.aspect.MyDoneTime;
import com.gameley.dmgtpf.common.utils.Result;
import com.gameley.dmgtpf.kernel.entity.MobileEntity;
import com.gameley.dmgtpf.kernel.service.MobileService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

/**
 * 
 *
 * @author libencheng
 * @email libencheng@gmail.com
 * @date 2021-07-29 17:57:32
 */
@RestController
@RequestMapping("kernel/mobile")
public class MobileController
{
    @Autowired
    private MobileService mobileService;
    
    @MyDoneTime(param = "MobileController.file2tableSava")
    @ResponseBody
    @RequestMapping("/file2tableSava")
    public String file2tableSava(HttpServletRequest request, HttpServletResponse response,
            @RequestParam(value = "file", required = false) MultipartFile file)
    {
        String msg = mobileService.file2tableSavaDB(file);
        return msg;
    }
    
    /**
     * 列表
     */
    @MyDoneTime(param = "MobileController.list")
    @RequestMapping("/list")
    @RequiresPermissions("kernel:mobile:list")
    public Result list(HttpServletRequest request, HttpServletResponse response, @RequestParam Map<String, Object> params)
    {
        
        QueryWrapper<MobileEntity> wrapper = new QueryWrapper<MobileEntity>();
        wrapper.allEq(params);
        
        List<MobileEntity> list = mobileService.list(wrapper);
        
        return Result.ok().put("page", list);
        
    }
    
    /**
     * 信息
     */
    @MyDoneTime(param = "MobileController.info")
    @RequestMapping("/info/{id}")
    @RequiresPermissions("kernel:mobile:info")
    public Result info(HttpServletRequest request, HttpServletResponse response, @PathVariable("id") Integer id)
    {
        MobileEntity mobile = mobileService.getById(id);
        
        return Result.ok().put("mobile", mobile);
    }
    
    /**
     * 保存
     */
    @MyDoneTime(param = "MobileController.save")
    @RequestMapping("/save")
    @RequiresPermissions("kernel:mobile:save")
    public Result save(HttpServletRequest request, HttpServletResponse response, @RequestBody MobileEntity mobile)
    {
        mobileService.save(mobile);
        
        return Result.ok();
    }
    
    /**
     * 修改
     */
    @MyDoneTime(param = "MobileController.update")
    @RequestMapping("/update")
    @RequiresPermissions("kernel:mobile:update")
    public Result update(HttpServletRequest request, HttpServletResponse response, @RequestBody MobileEntity mobile)
    {
        mobileService.updateById(mobile);
        
        return Result.ok();
    }
    
    /**
     * 删除
     */
    @MyDoneTime(param = "MobileController.delete")
    @RequestMapping("/delete")
    @RequiresPermissions("kernel:mobile:delete")
    public Result delete(HttpServletRequest request, HttpServletResponse response, @RequestBody Integer[] ids)
    {
        mobileService.removeByIds(Arrays.asList(ids));
        
        return Result.ok();
    }
    
}
